$("#deleteImg").css("height",$(window).height());
//todo 删除图片按钮
$("#previewImg p i").click(function(e){
    e.stopPropagation();
    $("#deleteImg").css("display","block");
    $(".sureDelete").css("display","block").addClass("sureDeleteShow").removeClass("sureDeleteHidden");
});
//取消按钮
$(".sureDelete .cancel").click(function(e){
    hidden(e);
});

$("#deleteImg").click(function(e){
    hidden(e);
});

//todo 隐藏删除图片弹框
function hidden(e){
    e.stopPropagation();
    $(".sureDelete").removeClass("sureDeleteShow").addClass("sureDeleteHidden");
    setTimeout(function(){
        $("#deleteImg").css("display","none");
    },500);
}

//todo 删除照片
$(".delete").click(function(e){
    e.stopPropagation();
    //删除的图片的index值
    var current_index=$("#previewImg .swiper-slide-active").attr("data-index");

    swiper.removeSlide(current_index);
    var totalNum=$("#previewImg .total").text();
    $("ul.pic").find("img[data-index='"+current_index+"']").parent().remove();
    if(totalNum==1){
        $("#previewImg").css("display","none");
        $("#deleteImg").css("display","none");
    }
    else{
        //todo 外面缩略图重排序
        for(var i=0;i<$(".pic img").length;i++){
            $($(".pic img")[i]).attr("data-index",i);
            if(i==$(".pic img").length-1){
                //todo .imgs 里的图片属性data-index重排序
                for(var j=0;j<$(".swiper-slide").length;j++){
                    $($(".swiper-slide")[j]).attr("data-index",j);
                    if(j==$(".imgs img").length-1){
                        totalNum=$(".swiper-slide").length;
                        $("#previewImg .total").text(totalNum);
                        if(totalNum<9){
                            $(".a-upload-box").css("display","inline-block");
                        }
                        $("#deleteImg").css("display","none");
                    }
                }
            }
        }
    }
});
